<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>协议编码设置</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/css/oksub.css">
    <script type="text/javascript" src="/static/lib/loading/okLoading.js"></script>
</head>
<body>
<div class="ok-body">
    <blockquote class="layui-elem-quote" style="margin: 5px 0px;">系统管理>业务设置>协议编码管理</blockquote>
    <!--模糊搜索区域-->
    <div class="layui-row">
        <form class="layui-form ok-search-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" style="width: 340px;" name="searchname" id="searchname" class="layui-input" placeholder="支持前缀/业务类型模糊查询" autocomplete="off"
                               name="serachname">
                    </div>
                </div>
                <button class="layui-btn" style="margin-left: 150px;margin-bottom: 10px;" lay-submit="" lay-filter="search">
                            <i class="layui-icon">&#xe615;</i>
                        </button>
            </div>
        </form>
    </div>
    <!--数据表格-->
    <table class="layui-hide" id="tableId" lay-filter="tableFilter"></table>
</div>
<!--js逻辑-->
<script src="/static/lib/layui/layui.js"></script>
<script>
    layui.use(["element", "jquery", "table", "form", "laydate", "okLayer", "okUtils", "okMock"], function () {
        let table = layui.table;
        let form = layui.form;
        let laydate = layui.laydate;
        let okLayer = layui.okLayer;
        let okUtils = layui.okUtils;
        let okMock = layui.okMock;
        let $ = layui.jquery;
        okLoading.close($);


        let userTable = table.render({
            elem: '#tableId',
            url: '{% url "business:rules_list" %}',
            limit: 20,
            height: 'full-120',
            page: true,
            toolbar: "#toolbarTpl",
            size: "sm",
            cols: [[
                {type: "checkbox", fixed: "left"},
                {field: "id", title: "ID", width: 60, sort: true},
                {field: "rule_perfix", title: "前缀", width: 200},
                {field: "type_name", title: "业务类型", width: 200},
                {field: "rule_year", title: "年份", width: 200},
                {field: "rule_begin", title: "起始数字", width: 200},
                {field: "type_id", title: "业务类型id", width: 100, hide:true},
                {field: "rule_nownum", title: "已有业务笔数", width: 150},
                {field: "rule_suffix", title: "生成位数", width: 150},
                {field: "remark_describe", title: "备注", width: 200},
                {field: "create_time", title: "创建时间", width: 200},
                {title: "操作", align: "center", width: 150, fixed: "right", templet: "#operationTpl"}
            ]],
            done: function (res, curr, count) {

            }
        });
        // 这个地方说了个寂寞

        table.on("toolbar(tableFilter)", function (obj) {
            switch (obj.event) {
                case "batchDel":
                    batchDel();
                    break;
                case "add":
                    add();
                    break;
                case "dateset":
                    dateset();
                    break;
            }
        });

        table.on("tool(tableFilter)", function (obj) {
            let data = obj.data;
            switch (obj.event) {
                case "edit":
                    edit(data);
                    break;
                case "del":
                    del(data);
                    break;
            }
        });

        function add() {
            okLayer.open("添加规则", "{% url 'business:rules_insert_view' %}", "90%", "90%", null, function () {
                userTable.reload();
            })
        }

        function edit(data) {
            okLayer.open("修改规则", "{% url 'business:rules_edit_view' %}", "90%", "90%", function (layero, index) {
                let iframe = window['layui-layer-iframe' + index];
                iframe.child(data);
            })
        }
        function del(data) {
            okLayer.confirm("确定要删除吗？", function () {
                okUtils.ajax("/business/rules_del/" + data.id, "post", data.field, true).done(function (response) {
                    okUtils.tableSuccessMsg(response.msg);
                }).fail(function (error) {
                    console.log(error)
                });
            })
        }
        function dateset() {
            var myDate = new Date;
            var nowyear = myDate.getFullYear();
            var datedate={'date':nowyear}
            okLayer.confirm("确定要调整年度到"+nowyear+"？", function () {
                okUtils.ajax("/business/rules_dateset/","post",datedate,true).done(function (response) {
                    okUtils.tableSuccessMsg(response.msg);
                }).fail(function (error) {
                    console.log(error)
                });
            })
        }
        form.on("submit(search)", function (data) {
			userTable.reload({
                url: "{% url 'business:rules_search' %}",
				request: {
                    pageName: 'page' //页码的参数名称，默认：page
                    ,limitName: 'limit' //每页数据量的参数名，默认：limit
                },
				page: {curr: 1},
                where:{
                    "searchname":$('#searchname').val()
                }
			});
			return false;
    })});
</script>
<!-- 头工具栏模板 -->
<script type="text/html" id="toolbarTpl">
    {% for l in data %}
        {% if l.menu_code == '50010201' %}
        <button class="layui-btn layui-btn-sm layui-btn-normal" lay-event="add"><i class="layui-icon">&#xe608;</i>添加规则</button>
        {% elif l.menu_code == '50010204' %}
        <button class="layui-btn layui-btn-sm" lay-event="dateset"><i class="layui-icon">&#xe716;</i>年度处理</button>
    {% endif %}
{% endfor %}
</script>
<!-- 行工具栏模板 -->
<script type="text/html" id="operationTpl">
    {% for l in data %}
        {% if l.menu_code == '50010202' %}
    <a href="javascript:" title="编辑" lay-event="edit"><button class="layui-btn layui-btn-xs">编辑</button></a>
    &nbsp;  {% elif l.menu_code == '50010203' %}
    <a href="javascript:" title="删除" lay-event="del"><button class="layui-btn layui-btn-danger layui-btn-xs">删除</button></a>
    {% endif %}
    {% endfor %}
</script>

</body>
</html>
